import './public/toastr'
import server from './date/url'

let $btn_start = $('#start')

$btn_start.on('click', function(e) {
  e.preventDefault()

  loading()  

  $.ajax({
    url: server,
    type: 'POST',
    data: {
      task: '2login',
      stamp: new Date().getTime()
    }
  })
  .done(function(res) {
    console.log("success")
    console.log(res)

    if (res.status) {
      window.location = '/login.html'
    } else {
      layer.msg(res.message || '', {
        time: 2000
      })
    }

  })
  .fail(function(res) {
    console.log("error")
    console.log(res)
  })
  .always(function() {
    // console.log("complete")
    closeLoading()
  })
  

})

let loadingLayer

function loading() {
  loadingLayer = layer.msg('加载中', {
    icon: 16,
    shade: .6,
    time: 0
  })
}

function closeLoading() {
  layer.close(loadingLayer)
}